package com.lanou.tipsy.adapter.songList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou.tipsy.R;
import com.lanou.tipsy.entity.songList.songslist.ChildrenEntity;

import java.util.ArrayList;

/**
 * Created by dllo on 15/10/31.
 *
 *
 *   歌单分类菜单 适配器  菜单的5个GridView共用一个适配器
 */
public class SongListMenuAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<ChildrenEntity> data;
    public SongListMenuAdapter(Context context, ArrayList<ChildrenEntity> data){
        this.context = context;
        this.data = data;
    }
    @Override
    public int getCount() {
        return data != null && data.size() > 0 ? data.size() : 0;
    }

    @Override
    public ChildrenEntity getItem(int position) {
        return data != null && data.size() > 0 ? data.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_fr_songlist_menu,null);
            holder = new ViewHolder();
            holder.tag = (TextView) convertView.findViewById(R.id.bt);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        ChildrenEntity tag = (ChildrenEntity) getItem(position);
        if ( tag != null ){
            holder.tag.setText(tag.getTag());
        }
        return convertView;
    }
    private class ViewHolder{
        public TextView tag;
    }
}
